﻿using System;
using System.IO;
using System.Drawing.Imaging;

namespace TileMaker
{
    public static class Miscallenous
    {
        public static string PixelFormatFancy(PixelFormat format)
        {
            switch (format)
            {
                case PixelFormat.Format16bppArgb1555:
                    return "16bpp ARGB";
                case PixelFormat.Format16bppGrayScale:
                    return "16bpp Gray";
                case PixelFormat.Format16bppRgb555:
                    return "16bpp RGB";
                case PixelFormat.Format16bppRgb565:
                    return "16bpp RGB";
                case PixelFormat.Format1bppIndexed:
                    return "1bpp Indexed";
                case PixelFormat.Format24bppRgb:
                    return "24bpp RGB";
                case PixelFormat.Format32bppArgb:
                    return "32bpp ARGB";
                case PixelFormat.Format32bppPArgb:
                    return "32bpp Premultiplied ARGB";
                case PixelFormat.Format32bppRgb:
                    return "32bpp RGB";
                case PixelFormat.Format48bppRgb:
                    return "48bpp RGB";
                case PixelFormat.Format4bppIndexed:
                    return "4bpp Indexed";
                case PixelFormat.Format64bppArgb:
                    return "64bpp ARGB";
                case PixelFormat.Format64bppPArgb:
                    return "64bpp Premultiplied ARGB";
                case PixelFormat.Format8bppIndexed:
                    return "8bpp Indexed";
                default:
                    return format.ToString();
            }
        }

        public static Func<ulong, bool> IsPowerOfTwo = x => (x & (x - 1))== 0;
        public static Func<ulong, bool> DividibleBy512 = x => Math.IEEERemainder(x, 512) == 0;

        public static long GetDirectorySize(string p)
        {
            // 1.
            // Get array of all file names.
            string[] a = Directory.GetFiles(p, "*.*");

            // 2.
            // Calculate total bytes of all files in a loop.
            long b = 0;
            foreach (string name in a)
            {
                // 3.
                // Use FileInfo to get length of each file.
                FileInfo info = new FileInfo(name);
                b += info.Length;
            }
            // 4.
            // Return total size
            return b;
        }
    }
}
